<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ title }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('投资主体')" prop="investmentId">
        <el-select v-model="queryParams.investmentId" :placeholder="$t('投资主体')">
          <el-option
            v-for="dict in investorOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['case:case:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dealCathayCaseList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('主体名称')" align="center" prop="investorName">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.investorName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('报告时间')" align="center" prop="reportDate" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('Actual business development')" align="center" prop="initialCaseAssumptions" show-overflow-tooltip />
      <el-table-column :label="$t('创建时间')" align="center" prop="reportDate" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('修改时间')" align="center" prop="reportDate" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['case:case:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['case:case:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改Cathay Case对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealCathayCaseForm ref="dealCathayCaseForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealCathayCase, delDealCathayCase } from '@/api/sass/kaihui/case/dealCathayCase'
import { listDealInvestmentAll } from '@/api/deal/investment/dealInvestment.js'
import dealCathayCaseForm from './dealCathayCaseForm.vue'
export default {
    components: {
        dealCathayCaseForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // Cathay Case表格数据
          dealCathayCaseList: [],
          // 弹出层标题
          title: 'Revised exit cases',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              type: 'reviesed',
              dealId: this.$route.query.id,
              investmentId: undefined,
              initialCaseAssumptions: undefined,
              mainAssumptions: undefined,
              upsideAssumptions: undefined,
              downsideAssumptions: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
        investorOptions: []
      }
  },
  created() {
      this.getList()
    listDealInvestmentAll({ dealId: this.$route.query.id }).then(response => {
      console.log(response.data)
      if (response.data !== null && response.data !== undefined) {
        response.data.forEach(item => {
          const option = {
            dictLabel: item.investorName,
            dictValue: item.id
          }
          this.investorOptions.push(option)
        })
      }
    })
  },
  methods: {
    /** 查询Cathay Case列表 */
    getList() {
        this.loading = true
        listDealCathayCase(this.queryParams).then(response => {
            this.dealCathayCaseList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            const data = {
              type: 'reviesed',
              dealId: this.$route.query.id
            }
            this.$refs.dealCathayCaseForm.init(data)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealCathayCaseForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delDealCathayCase(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
        })
    }
  }
}
</script>
